using System;
using System.Collections.Generic;
using System.IO;
using NHibernate;
using NHibernate.Cfg;

namespace SIP.PN.Infraestructura.NHibernate
{
    public class SessionFactoryProvider
    {
        private IDictionary<string, ISessionFactory> sessionFactories = new Dictionary<string, ISessionFactory>();

        public SessionFactoryProvider()
        {
            Configuration cfgWEB = new Configuration();
            cfgWEB.Configure(GetConfigurationFilePath("hibernate.web.cfg.xml"));
            sessionFactories.Add("WEB", cfgWEB.BuildSessionFactory());
        }

        public ISessionFactory GetSessionFactory(string sessionFactoryId)
        {
            return sessionFactories[sessionFactoryId];
        }

        private static string GetConfigurationFilePath(string fileName)
        {
            string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            string relativeSearchPath = AppDomain.CurrentDomain.RelativeSearchPath;
            string str3 = (relativeSearchPath == null) ? baseDirectory : Path.Combine(baseDirectory, relativeSearchPath);
            return Path.Combine(str3, fileName);
        }
    }
}